Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating the time series standard deviations of 5-year rolling winods of X_{t}

    Hello. I am working on compustat and I would like to generate the time series standard deviations of 5-year rolling winods of Sales. Specifically, the time series for the volatility of X_{t} is

    \sigma(X_{t}) = \sqrt{\frac{\sum_{\tau = t-2}^{t+3} (X_{\tau} - \Bar{X}_{t})^2}{5}}

    Can any one please help?

  • #2


    The window for time t from t - 2 to t + 3 includes six data points, for t - 2, t - 1, t, t + 1, t + 2, t + 3.

    rangestat from SSC is one of several ways to do this. You must install before you can use it.

    Code:
    ssc install rangestat 
    Here is an example:

    Code:
    . webuse grunfeld, clear
    
    . rangestat (count) invest (sd) invest, int(year -2 3) by(company)
    
    . l company year invest* in 1/10
    
         +------------------------------------------------+
         | company   year   invest   invest~t   invest_sd |
         |------------------------------------------------|
      1. |       1   1935    317.6          4   70.390162 |
      2. |       1   1936    391.8          5   61.263442 |
      3. |       1   1937    410.6          6   73.366271 |
      4. |       1   1938    257.7          6   90.875925 |
      5. |       1   1939    330.8          6   93.461273 |
         |------------------------------------------------|
      6. |       1   1940    461.2          6   101.54846 |
      7. |       1   1941      512          6   75.513829 |
      8. |       1   1942      448          6   45.189044 |
      9. |       1   1943    499.6          6   81.577725 |
     10. |       1   1944    547.5          6   80.591789 |
         +------------------------------------------------+
    
    . su invest in 1/6
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
          invest |          6    361.6167    73.36627      257.7      461.2

    Comment


    • #3
      Thank you Nick. Really helpful!

      Comment

      Working...
      X